﻿/*
 * Copyright (c) 2010 Piotr Polesiuk
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

using System.Drawing;
using System.Windows.Forms;

namespace Fotometr
{
    class ImagePanel : Panel
    {
        public ImagePanel() : base()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (Core.Bitmap != null)
                e.Graphics.DrawImage(Core.Bitmap, 0, 0, Core.Bitmap.Width * Core.Scale, Core.Bitmap.Height * Core.Scale);

            if (Core.SelectedTool == Core.Tool.Foto1)
            {
                float rad = Core.Foto1Radius * Core.Scale;
                Pen pen = new Pen(Color.White);
                e.Graphics.DrawEllipse(pen, Core.CursorPositionX - rad, Core.CursorPositionY - rad, 2 * rad - 1, 2 * rad - 1);
            }
            else if (Core.SelectedTool == Core.Tool.Foto3)
            {
                float rad1 = Core.Foto3Radius1 * Core.Scale;
                float rad2 = Core.Foto3Radius2 * Core.Scale;
                float rad3 = Core.Foto3Radius3 * Core.Scale;
                Pen pen = new Pen(Color.White);
                e.Graphics.DrawEllipse(pen, Core.CursorPositionX - rad1, Core.CursorPositionY - rad1, 2 * rad1 - 1, 2 * rad1 - 1);
                e.Graphics.DrawEllipse(pen, Core.CursorPositionX - rad2, Core.CursorPositionY - rad2, 2 * rad2 - 1, 2 * rad2 - 1);
                e.Graphics.DrawEllipse(pen, Core.CursorPositionX - rad3, Core.CursorPositionY - rad3, 2 * rad3 - 1, 2 * rad3 - 1);
            }
        }
    }
}
